// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.IndexManagement;

public sealed partial class AddAction
{
	/// <summary>
	/// <para>Alias for the action.<br/>Index alias names support date math.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("alias")]
	public Elastic.Clients.Elasticsearch.Serverless.IndexAlias? Alias { get; set; }

	/// <summary>
	/// <para>Aliases for the action.<br/>Index alias names support date math.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("aliases")]
	[SingleOrManyCollectionConverter(typeof(Elastic.Clients.Elasticsearch.Serverless.IndexAlias))]
	public ICollection<Elastic.Clients.Elasticsearch.Serverless.IndexAlias>? Aliases { get; set; }

	/// <summary>
	/// <para>Query used to limit documents the alias can access.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("filter")]
	public Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query? Filter { get; set; }

	/// <summary>
	/// <para>Data stream or index for the action.<br/>Supports wildcards (`*`).</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("index")]
	public Elastic.Clients.Elasticsearch.Serverless.IndexName? Index { get; set; }

	/// <summary>
	/// <para>Value used to route indexing operations to a specific shard.<br/>If specified, this overwrites the `routing` value for indexing operations.<br/>Data stream aliases don’t support this parameter.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("index_routing")]
	public Elastic.Clients.Elasticsearch.Serverless.Routing? IndexRouting { get; set; }

	/// <summary>
	/// <para>Data streams or indices for the action.<br/>Supports wildcards (`*`).</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("indices")]
	public Elastic.Clients.Elasticsearch.Serverless.Indices? Indices { get; set; }

	/// <summary>
	/// <para>If `true`, the alias is hidden.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("is_hidden")]
	public bool? IsHidden { get; set; }

	/// <summary>
	/// <para>If `true`, sets the write index or data stream for the alias.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("is_write_index")]
	public bool? IsWriteIndex { get; set; }

	/// <summary>
	/// <para>If `true`, the alias must exist to perform the action.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("must_exist")]
	public bool? MustExist { get; set; }

	/// <summary>
	/// <para>Value used to route indexing and search operations to a specific shard.<br/>Data stream aliases don’t support this parameter.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("routing")]
	public Elastic.Clients.Elasticsearch.Serverless.Routing? Routing { get; set; }

	/// <summary>
	/// <para>Value used to route search operations to a specific shard.<br/>If specified, this overwrites the `routing` value for search operations.<br/>Data stream aliases don’t support this parameter.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("search_routing")]
	public Elastic.Clients.Elasticsearch.Serverless.Routing? SearchRouting { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.Serverless.IndexManagement.IndexUpdateAliasesAction(AddAction addAction) => Elastic.Clients.Elasticsearch.Serverless.IndexManagement.IndexUpdateAliasesAction.Add(addAction);
}

public sealed partial class AddActionDescriptor<TDocument> : SerializableDescriptor<AddActionDescriptor<TDocument>>
{
	internal AddActionDescriptor(Action<AddActionDescriptor<TDocument>> configure) => configure.Invoke(this);

	public AddActionDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.IndexAlias? AliasValue { get; set; }
	private ICollection<Elastic.Clients.Elasticsearch.Serverless.IndexAlias>? AliasesValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query? FilterValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument> FilterDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument>> FilterDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.IndexName? IndexValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Routing? IndexRoutingValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Indices? IndicesValue { get; set; }
	private bool? IsHiddenValue { get; set; }
	private bool? IsWriteIndexValue { get; set; }
	private bool? MustExistValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Routing? RoutingValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Routing? SearchRoutingValue { get; set; }

	/// <summary>
	/// <para>Alias for the action.<br/>Index alias names support date math.</para>
	/// </summary>
	public AddActionDescriptor<TDocument> Alias(Elastic.Clients.Elasticsearch.Serverless.IndexAlias? alias)
	{
		AliasValue = alias;
		return Self;
	}

	/// <summary>
	/// <para>Aliases for the action.<br/>Index alias names support date math.</para>
	/// </summary>
	public AddActionDescriptor<TDocument> Aliases(ICollection<Elastic.Clients.Elasticsearch.Serverless.IndexAlias>? aliases)
	{
		AliasesValue = aliases;
		return Self;
	}

	/// <summary>
	/// <para>Query used to limit documents the alias can access.</para>
	/// </summary>
	public AddActionDescriptor<TDocument> Filter(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query? filter)
	{
		FilterDescriptor = null;
		FilterDescriptorAction = null;
		FilterValue = filter;
		return Self;
	}

	public AddActionDescriptor<TDocument> Filter(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument> descriptor)
	{
		FilterValue = null;
		FilterDescriptorAction = null;
		FilterDescriptor = descriptor;
		return Self;
	}

	public AddActionDescriptor<TDocument> Filter(Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument>> configure)
	{
		FilterValue = null;
		FilterDescriptor = null;
		FilterDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>Data stream or index for the action.<br/>Supports wildcards (`*`).</para>
	/// </summary>
	public AddActionDescriptor<TDocument> Index(Elastic.Clients.Elasticsearch.Serverless.IndexName? index)
	{
		IndexValue = index;
		return Self;
	}

	/// <summary>
	/// <para>Value used to route indexing operations to a specific shard.<br/>If specified, this overwrites the `routing` value for indexing operations.<br/>Data stream aliases don’t support this parameter.</para>
	/// </summary>
	public AddActionDescriptor<TDocument> IndexRouting(Elastic.Clients.Elasticsearch.Serverless.Routing? indexRouting)
	{
		IndexRoutingValue = indexRouting;
		return Self;
	}

	/// <summary>
	/// <para>Data streams or indices for the action.<br/>Supports wildcards (`*`).</para>
	/// </summary>
	public AddActionDescriptor<TDocument> Indices(Elastic.Clients.Elasticsearch.Serverless.Indices? indices)
	{
		IndicesValue = indices;
		return Self;
	}

	/// <summary>
	/// <para>If `true`, the alias is hidden.</para>
	/// </summary>
	public AddActionDescriptor<TDocument> IsHidden(bool? isHidden = true)
	{
		IsHiddenValue = isHidden;
		return Self;
	}

	/// <summary>
	/// <para>If `true`, sets the write index or data stream for the alias.</para>
	/// </summary>
	public AddActionDescriptor<TDocument> IsWriteIndex(bool? isWriteIndex = true)
	{
		IsWriteIndexValue = isWriteIndex;
		return Self;
	}

	/// <summary>
	/// <para>If `true`, the alias must exist to perform the action.</para>
	/// </summary>
	public AddActionDescriptor<TDocument> MustExist(bool? mustExist = true)
	{
		MustExistValue = mustExist;
		return Self;
	}

	/// <summary>
	/// <para>Value used to route indexing and search operations to a specific shard.<br/>Data stream aliases don’t support this parameter.</para>
	/// </summary>
	public AddActionDescriptor<TDocument> Routing(Elastic.Clients.Elasticsearch.Serverless.Routing? routing)
	{
		RoutingValue = routing;
		return Self;
	}

	/// <summary>
	/// <para>Value used to route search operations to a specific shard.<br/>If specified, this overwrites the `routing` value for search operations.<br/>Data stream aliases don’t support this parameter.</para>
	/// </summary>
	public AddActionDescriptor<TDocument> SearchRouting(Elastic.Clients.Elasticsearch.Serverless.Routing? searchRouting)
	{
		SearchRoutingValue = searchRouting;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (AliasValue is not null)
		{
			writer.WritePropertyName("alias");
			JsonSerializer.Serialize(writer, AliasValue, options);
		}

		if (AliasesValue is not null)
		{
			writer.WritePropertyName("aliases");
			SingleOrManySerializationHelper.Serialize<Elastic.Clients.Elasticsearch.Serverless.IndexAlias>(AliasesValue, writer, options);
		}

		if (FilterDescriptor is not null)
		{
			writer.WritePropertyName("filter");
			JsonSerializer.Serialize(writer, FilterDescriptor, options);
		}
		else if (FilterDescriptorAction is not null)
		{
			writer.WritePropertyName("filter");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument>(FilterDescriptorAction), options);
		}
		else if (FilterValue is not null)
		{
			writer.WritePropertyName("filter");
			JsonSerializer.Serialize(writer, FilterValue, options);
		}

		if (IndexValue is not null)
		{
			writer.WritePropertyName("index");
			JsonSerializer.Serialize(writer, IndexValue, options);
		}

		if (IndexRoutingValue is not null)
		{
			writer.WritePropertyName("index_routing");
			JsonSerializer.Serialize(writer, IndexRoutingValue, options);
		}

		if (IndicesValue is not null)
		{
			writer.WritePropertyName("indices");
			JsonSerializer.Serialize(writer, IndicesValue, options);
		}

		if (IsHiddenValue.HasValue)
		{
			writer.WritePropertyName("is_hidden");
			writer.WriteBooleanValue(IsHiddenValue.Value);
		}

		if (IsWriteIndexValue.HasValue)
		{
			writer.WritePropertyName("is_write_index");
			writer.WriteBooleanValue(IsWriteIndexValue.Value);
		}

		if (MustExistValue.HasValue)
		{
			writer.WritePropertyName("must_exist");
			writer.WriteBooleanValue(MustExistValue.Value);
		}

		if (RoutingValue is not null)
		{
			writer.WritePropertyName("routing");
			JsonSerializer.Serialize(writer, RoutingValue, options);
		}

		if (SearchRoutingValue is not null)
		{
			writer.WritePropertyName("search_routing");
			JsonSerializer.Serialize(writer, SearchRoutingValue, options);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class AddActionDescriptor : SerializableDescriptor<AddActionDescriptor>
{
	internal AddActionDescriptor(Action<AddActionDescriptor> configure) => configure.Invoke(this);

	public AddActionDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.IndexAlias? AliasValue { get; set; }
	private ICollection<Elastic.Clients.Elasticsearch.Serverless.IndexAlias>? AliasesValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query? FilterValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor FilterDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor> FilterDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.IndexName? IndexValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Routing? IndexRoutingValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Indices? IndicesValue { get; set; }
	private bool? IsHiddenValue { get; set; }
	private bool? IsWriteIndexValue { get; set; }
	private bool? MustExistValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Routing? RoutingValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Routing? SearchRoutingValue { get; set; }

	/// <summary>
	/// <para>Alias for the action.<br/>Index alias names support date math.</para>
	/// </summary>
	public AddActionDescriptor Alias(Elastic.Clients.Elasticsearch.Serverless.IndexAlias? alias)
	{
		AliasValue = alias;
		return Self;
	}

	/// <summary>
	/// <para>Aliases for the action.<br/>Index alias names support date math.</para>
	/// </summary>
	public AddActionDescriptor Aliases(ICollection<Elastic.Clients.Elasticsearch.Serverless.IndexAlias>? aliases)
	{
		AliasesValue = aliases;
		return Self;
	}

	/// <summary>
	/// <para>Query used to limit documents the alias can access.</para>
	/// </summary>
	public AddActionDescriptor Filter(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query? filter)
	{
		FilterDescriptor = null;
		FilterDescriptorAction = null;
		FilterValue = filter;
		return Self;
	}

	public AddActionDescriptor Filter(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor descriptor)
	{
		FilterValue = null;
		FilterDescriptorAction = null;
		FilterDescriptor = descriptor;
		return Self;
	}

	public AddActionDescriptor Filter(Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor> configure)
	{
		FilterValue = null;
		FilterDescriptor = null;
		FilterDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>Data stream or index for the action.<br/>Supports wildcards (`*`).</para>
	/// </summary>
	public AddActionDescriptor Index(Elastic.Clients.Elasticsearch.Serverless.IndexName? index)
	{
		IndexValue = index;
		return Self;
	}

	/// <summary>
	/// <para>Value used to route indexing operations to a specific shard.<br/>If specified, this overwrites the `routing` value for indexing operations.<br/>Data stream aliases don’t support this parameter.</para>
	/// </summary>
	public AddActionDescriptor IndexRouting(Elastic.Clients.Elasticsearch.Serverless.Routing? indexRouting)
	{
		IndexRoutingValue = indexRouting;
		return Self;
	}

	/// <summary>
	/// <para>Data streams or indices for the action.<br/>Supports wildcards (`*`).</para>
	/// </summary>
	public AddActionDescriptor Indices(Elastic.Clients.Elasticsearch.Serverless.Indices? indices)
	{
		IndicesValue = indices;
		return Self;
	}

	/// <summary>
	/// <para>If `true`, the alias is hidden.</para>
	/// </summary>
	public AddActionDescriptor IsHidden(bool? isHidden = true)
	{
		IsHiddenValue = isHidden;
		return Self;
	}

	/// <summary>
	/// <para>If `true`, sets the write index or data stream for the alias.</para>
	/// </summary>
	public AddActionDescriptor IsWriteIndex(bool? isWriteIndex = true)
	{
		IsWriteIndexValue = isWriteIndex;
		return Self;
	}

	/// <summary>
	/// <para>If `true`, the alias must exist to perform the action.</para>
	/// </summary>
	public AddActionDescriptor MustExist(bool? mustExist = true)
	{
		MustExistValue = mustExist;
		return Self;
	}

	/// <summary>
	/// <para>Value used to route indexing and search operations to a specific shard.<br/>Data stream aliases don’t support this parameter.</para>
	/// </summary>
	public AddActionDescriptor Routing(Elastic.Clients.Elasticsearch.Serverless.Routing? routing)
	{
		RoutingValue = routing;
		return Self;
	}

	/// <summary>
	/// <para>Value used to route search operations to a specific shard.<br/>If specified, this overwrites the `routing` value for search operations.<br/>Data stream aliases don’t support this parameter.</para>
	/// </summary>
	public AddActionDescriptor SearchRouting(Elastic.Clients.Elasticsearch.Serverless.Routing? searchRouting)
	{
		SearchRoutingValue = searchRouting;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (AliasValue is not null)
		{
			writer.WritePropertyName("alias");
			JsonSerializer.Serialize(writer, AliasValue, options);
		}

		if (AliasesValue is not null)
		{
			writer.WritePropertyName("aliases");
			SingleOrManySerializationHelper.Serialize<Elastic.Clients.Elasticsearch.Serverless.IndexAlias>(AliasesValue, writer, options);
		}

		if (FilterDescriptor is not null)
		{
			writer.WritePropertyName("filter");
			JsonSerializer.Serialize(writer, FilterDescriptor, options);
		}
		else if (FilterDescriptorAction is not null)
		{
			writer.WritePropertyName("filter");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor(FilterDescriptorAction), options);
		}
		else if (FilterValue is not null)
		{
			writer.WritePropertyName("filter");
			JsonSerializer.Serialize(writer, FilterValue, options);
		}

		if (IndexValue is not null)
		{
			writer.WritePropertyName("index");
			JsonSerializer.Serialize(writer, IndexValue, options);
		}

		if (IndexRoutingValue is not null)
		{
			writer.WritePropertyName("index_routing");
			JsonSerializer.Serialize(writer, IndexRoutingValue, options);
		}

		if (IndicesValue is not null)
		{
			writer.WritePropertyName("indices");
			JsonSerializer.Serialize(writer, IndicesValue, options);
		}

		if (IsHiddenValue.HasValue)
		{
			writer.WritePropertyName("is_hidden");
			writer.WriteBooleanValue(IsHiddenValue.Value);
		}

		if (IsWriteIndexValue.HasValue)
		{
			writer.WritePropertyName("is_write_index");
			writer.WriteBooleanValue(IsWriteIndexValue.Value);
		}

		if (MustExistValue.HasValue)
		{
			writer.WritePropertyName("must_exist");
			writer.WriteBooleanValue(MustExistValue.Value);
		}

		if (RoutingValue is not null)
		{
			writer.WritePropertyName("routing");
			JsonSerializer.Serialize(writer, RoutingValue, options);
		}

		if (SearchRoutingValue is not null)
		{
			writer.WritePropertyName("search_routing");
			JsonSerializer.Serialize(writer, SearchRoutingValue, options);
		}

		writer.WriteEndObject();
	}
}